<template>
	<view class="content">
		<view class="goods-evaluate-box">
			<view class="goods-info-box">
				<view class="goods-img-box"><image :src="info.image" mode=""></image></view>
				<view class="goods-title-box"><text>{{ info.store_name }}</text></view>
			</view>
			<view class="content-box">
				<textarea v-model="content" placeholder="期待你的评价..." placeholder-style="color:#CCC"></textarea>
			</view>
			<view class="upload-img-box">
				<view class="title-box">
					<text>上传照片</text>
				</view>
				<view class="input-box">
					<view class="upload-img-box flex-c-w">
						<view class="upload-img-box-item" v-for="(item, index) in imgList" @click="bindImgPreview(item.path)" :key="index">
							<image :src="item.path" mode="aspectFill"></image>
							<view class="del" @click.stop="bindDel(index)">
								<image src="/pageMember/static/icon12.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="upload-img-item" @click="bindAddImg">
						    <image src="../static/icon11.png" mode="widthFix"></image>
						</view>
					</view>
				</view>
			</view>
			<view class="pf-box">
				<text>商品评分：</text>
				<u-rate :count="count" size="30" active-color="#FCC526" v-model="star"></u-rate>
			</view>
		</view>
		<view class="wl-box bg-white">
			<text>物流评分：</text>
			<u-rate :count="count" size="30" active-color="#FCC526" v-model="logistics_star"></u-rate>
		</view>
		<view class="bottom-plate-box">
			<!-- 底部but -->
			<view class="bottom-but-box" @click="submitFun">
				<text>提交评价</text>
			</view>
		</view>
	</view>
</template>

<script>
	let channel
	export default {
		data(){
			return {
				info: {}, // 页面基本信息
				order_id: '', // 订单号
				content: '', // 评价信息
				imgList: [], // 图片列表
				count: 5, // 星级评分等级
				star: 0, // 商品评分
				logistics_star: 0, // 物流评分
			}
		},
		onLoad(option) {
			const { order_id } = option
			this.order_id = order_id || ''
			this.getInfo()
			channel = this.getOpenerEventChannel()
		},
		methods:{
			// 获取页面信息
			getInfo: async function () {
				uni.showLoading({ title: '加载中' })
				const { order_id } = this
				const { code, data, message } = await this.$u.api.getEvaluatePage({ order_id })
				if (code == '1') {
					console.log('评价页面信息', data)
					this.info = data
				} else {
					this.$showToast(message || '获取内容失败')
				}
			},
			bindAddImg(){ // 图片上传
				this.$uploadPic(9, res => {
					const { imgList } = this
					this.imgList = [...imgList, ...res]
				})
			},
			// 图片预览
			bindImgPreview: function (current) {
				const { imgList, urls = imgList.map(item => item.path) } = this
				uni.previewImage({
					current,
					urls
				})
			},
			// 删除图片
			bindDel: function (index) {
				this.imgList.splice(index, 1)
			},
			// 提交方法
			submitFun: async function () {
				const {
					content,
					info: { product_id, order_id },
					star,
					logistics_star,
					imgList,
				} = this
				if (!content) {
					this.$showToast('请输入评论内容')
					return
				}
				if (!star || !logistics_star) {
					this.$showToast('请选择评价星级')
					return
				}
				const param = {
					product_id,
					image: imgList.map(item => item.id).join(','),
					star,
					logistics_star,
					content,
					order_id,
				}
				console.log(param)
				uni.showLoading({ title: '加载中', mask: true })
				const { code, data, message } = await this.$u.api.setEvaluateHall(param)
				if (code == '1') {
					console.log('评价结果', data)
					channel.emit('changeStatus', true)
					uni.redirectTo({
						url: '/pageMember/tarbar/submitSuccess?status=2'
					})
				} else {
					this.$showToast(message || '提交失败')
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width: 100%;
		height: calc(100vh - 300rpx);
		overflow: hidden;
		overflow-y: auto;
		font-family: Microsoft YaHei;
		box-sizing: border-box;
		background: white;
		.goods-evaluate-box{
			padding: 20rpx;
			background: #fff;
			margin-bottom: 20rpx;
			.goods-info-box{
				display: flex;
				margin-bottom: 40rpx;
				.goods-img-box{
					flex: 0.2;
					line-height: 0;
					image{width: 120rpx; height: 120rpx;border-radius: 10rpx;}
				}
				.goods-title-box{
					flex: 0.8;
					align-self: center;
					font-size: 30rpx;
					font-weight: bold;
					color: #000000;
				}
			}
			.content-box{
				width: 100%;
				margin-bottom: 30rpx;
				textarea{width: 94%;height: 200rpx;padding: 20rpx;background: #F5F6FA;}
			}
			.upload-img-box{
				.title-box{
					padding-bottom: 30rpx;
					font-size: 30rpx;
					font-weight: bold;
					color: #333333;
				}
				.input-box{
					position: relative;
					width: 100%;
					input{
						font-size: 30rpx;
						font-weight: 400;
						padding: 30rpx;
						border: 1rpx solid #000;
						border-radius: 20rpx;
					}
					.upload-img-box{
						width: 100%;
						.upload-img-box-item{
							position: relative;
							line-height: 0;
							image{width: 210rpx;height: 210rpx;margin: 0 20rpx 20rpx 0;}
							.del{
								position: absolute;
								top: 0;
								right: 20rpx;
								image{width: 35rpx; height: 35rpx;margin: auto;}
							}
						}
						.upload-img-item{
							width: 210rpx;
							height: 210rpx;
							background: #F5F6FA;
							margin-bottom: 20rpx;
							display: flex; justify-content: center; align-items: center;
							image{width: 60rpx;height: 60rpx;}
						}
					}
				}
			}
			.pf-box{
				padding: 20rpx 0;
				font-size: 30rpx;
				font-weight: bold;
				color: #333333;
			}
		}
		.wl-box{
			width: 100%;
			padding: 40rpx 20rpx;
			font-size: 30rpx;
			font-weight: bold;
			color: #333333;
			border-top: 20rpx solid #F5F5F5;
		}
		.bottom-plate-box{
			position: fixed;bottom: 0;left: 0;
			z-index: 100;
			width: 100%;
			padding: 0 20rpx;
			padding-bottom: 80rpx;
			background: #fff;
		.bottom-but-box{
			width: 100%;
			padding: 25rpx 0;
			background: #000;
			font-size: 30rpx;
			font-weight: 400;
			color: #FFFFFF;
			text-align: center;
			border-radius: 50rpx;
			}
		}
	}
</style>